home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 157_01 / qed3 < prev    next >
Text File  |  1987-10-10  |  7KB  |  336 lines

  1. /*  VERSION 0006  (DATE: 28/04/87)  (TIME: 13:48)  */
  2. /*
  3.     e (qed) screen editor
  4.  
  5.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  6.  
  7.     August-December 1981
  8.  
  9.     Modified: Aug-Dec    1984:    BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  10.               March        1985:    BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  11.  
  12.      FILE: qed3
  13.  
  14.     FUNCTIONS: putline,putoffset,putstatusline,putlineno,,putpage,
  15.             putmess,unmess,putstr,rewrite,calcoffset,
  16.             resetcursor,setstatusname
  17.  
  18.     PURPOSE: write text to screen
  19.  
  20. */
  21.  
  22. #include "qed.h"
  23.  
  24. putline(line,y)
  25. int line, y;
  26. {
  27.     char *getline();
  28.     register char *p, c;
  29.     int bright, lastcol, off, x;
  30.     register int nblank,cp;
  31.  
  32.     deleteline(0,y);
  33.     if (line <= lastl) {
  34.  
  35. #if (SCRNDIMMD)                    /* highlight blocked lines */
  36.         bright= line == cline;
  37.         if (blocking && !bright) {
  38.             if (to) bright= (line >= from) && (line <= to);
  39.             else bright= (line >= (from > cline ? cline : from)) &&
  40.             (line <= (from > cline ? from  : cline));
  41.             }
  42. #else                            /* dim blocked lines if screen is brite */
  43.         bright = YES;
  44.         if (blocking) {        /* dim blocked lines */
  45.             if (to) bright= !( (line >= from) && (line <= to) );
  46.             else bright= !( (line >= (from > cline ? cline : from)) &&
  47.             (line <= (from > cline ? from  : cline)) );
  48.             }
  49. #endif
  50.         
  51.         lastcol=SWIDTH;
  52.         off=x=0;
  53.         p=getline(line);
  54.         if ( (line == cline && calcoffset()) || (blockscroll && offset) ) {
  55.             lastcol+=offset-1;
  56.             off=offset;
  57.             x=1;
  58.             makedim(); 
  59.             putch('<');
  60.             makebright();
  61.             }
  62.  
  63.         if (!bright) makedim();
  64.  
  65.         for (cp=nblank=0; *p && cp < lastcol; p++) {
  66.             if (*p == '\t')
  67.                 do {
  68.                     if (cp >= off && cp < lastcol)
  69.                         nblank++;
  70.                     }
  71.             while (++cp % tabwidth);
  72.             else {
  73.                 if (cp++ >= off) {
  74.                     if (*p == ' ') nblank++;
  75.                     else {
  76.                         if (nblank)  {
  77.                             x+=nblank;
  78.                             if (nblank < GOTOLEN)
  79.                                 for (; nblank; nblank--)
  80.                                     _os(DIRIO,' ');
  81.                             else {
  82.                                 gotoxy(x,y);
  83.                                 nblank=0;
  84.                                 }
  85.                             }
  86.                         dispch(*p);
  87.                         x++;
  88.                         }
  89.                     }
  90.                 }
  91.             }
  92.         if (*p && y < SHEIGHT) {
  93.             if (bright) makedim(); 
  94.             else makebright();
  95.             putch('>');
  96.             }
  97.         makebright();
  98.             /* check for input and save if there at end of line */
  99.         if ( (c=_os(DIRIO,0xff))) inbuf[inbufp++]=c & ~PARBIT;
  100.         }
  101. }
  102.  
  103. putoffset()
  104. {
  105.     int i;
  106.  
  107.     gotoxy(0,0);
  108.     if (offset) for(i=3-uspr(offset,0L); i>0; i--) putch(' ');
  109.     else putstr("   ");
  110.     gotoxy(0,cursory);
  111. }
  112.  
  113. putstatusline(line)
  114. int line;
  115. {
  116.     deleteline(FNPOS,0);
  117.     makedim();
  118.     /*putstr(filename);*/
  119. /* put only the file name, not also path */
  120.     putstr(justfile);
  121.     putlineno(line);
  122.     makebright();
  123.     if (errmess != NULL) {
  124.         gotoxy(EMPOS,0);
  125.         putstr(errmess);
  126.         }
  127. }
  128.  
  129. putlineno(line)
  130. int line;
  131. {
  132.     int i;
  133.  
  134.     if (!displaypos) return;
  135.     gotoxy(LNPOS,0);
  136.     makedim();
  137.     i=uspr(line,0L);
  138.     putch(':');
  139.     for (i=8-i-uspr(cursorx+1,0L); i > 0; i--) _os(DIRIO,' ');
  140.     makebright();
  141. }
  142.  
  143. putpage()    /*display page more or less centered about 'cline'*/
  144. {
  145.     int y,line;
  146.     char c;
  147.  
  148.     pfirst= loc(cline,(topline-SHEIGHT)/2);
  149.     plast = loc(pfirst,SHEIGHT-topline);
  150.     putstatusline(cline);
  151.     for (line=pfirst, y=topline; line <= plast; line++, y++) {
  152.         if (cline == line) {
  153.             cursory = y;
  154.             cursorx = adjustc(cursorx);
  155.             }
  156.         putline(line,y);
  157.         if (inbufp && (cline != 1) && (cline != lastl) )
  158.             if(((c=inbuf[0]) == tran[DOWNPAGE])
  159.                  || (c == tran[UPPAGE])) return;
  160.         }
  161.     if (y <= SHEIGHT) delpage(y);
  162. }
  163.  
  164. putmess(message)
  165. char *message;
  166. {
  167.     int lines;
  168. /*    sint inc;*/
  169.     
  170.     if ((blankedmess) && (topline > blankedmess)) {
  171.         gotoxy(3,blankedmess++);
  172.         putstr(message);
  173.         return;
  174.         }
  175.  
  176.     if (topline == (helpon ? HELPLINES : 1)) lines=2;
  177.     else lines=1;
  178.     if (cursory <= (topline+=lines)) {
  179.          lines = cursory-(topline-lines);
  180.         cursory-=lines;
  181.         gotoxy(0,cursory);
  182.         for ( ; cursory < topline; cursory++) {
  183.                 insertline();
  184.                 if (plast != lastl) plast--;
  185.                 }
  186.         cursory+=lines;
  187.         }
  188.     else pfirst+= lines;
  189.     deleteline(0,topline-2);
  190.     deleteline(0,topline-1);
  191.     gotoxy(3,topline-2);
  192.     putstr(message);
  193. }
  194.  
  195. /* xprtmess -- if expert user, short message on statusline*/
  196. xprtmess(message)
  197. char *message;
  198. {
  199.     deleteline(EMPOS,0);
  200.     putstr(message);
  201.     blankedmess=NO;
  202. }
  203.  
  204. /* xmessoff -- blank expert prompt*/
  205. xmessoff()
  206. {
  207.     if (errmess==NULL) deleteline(EMPOS,0);
  208.     blankedmess=YES;
  209. }
  210.  
  211. /* unmess -- blank verbose prompt */
  212. unmess()
  213. {
  214.     int l, i, newtop, diff;
  215.  
  216.     newtop= (helpon ? HELPLINES : 1);
  217.     if (!(diff=(topline-newtop)) ) return;
  218.     if ((diff < PAGEOVERLAP) && ((pfirst-diff) < 1)) {
  219.         if (blankedmess == newtop) return;
  220.         for (l=newtop; l < topline; l++) deleteline(0,l);
  221.         blankedmess=newtop;
  222.         return;
  223.     }
  224.     blankedmess=NO;
  225.     if ((pfirst-=diff) < 1) {
  226.         topline=newtop;
  227.         putpage();
  228.     }
  229.     else {
  230.         pfirst=loc(pfirst,0);
  231.         for (l=newtop, i=0; l < topline; l++, i++) putline(pfirst+i,l);
  232.         topline=newtop;
  233.     }
  234. }
  235.  
  236. putstr(s)
  237. char *s;
  238. {
  239.     int dim;
  240.     char c;
  241.  
  242.     dim=NO;
  243.     while ( (c=*s++) )
  244.         switch(c) {
  245.         case BRIDIM :
  246.             (dim=!dim) ? begdim() : enddim(); 
  247.             break;
  248.         case '\n':    
  249.             putch('\r');
  250.         default  :    
  251.             putch(c);
  252.             }
  253.     if (dim) enddim();
  254. }
  255.  
  256. rewrite(cp,x)    /*rewrites current line from char 'cp', col 'x', onwards*/
  257. int cp, x;
  258. {
  259.     int i, begmark;
  260.     char cc,c;
  261.  
  262.     begmark= (calcoffset() > 0);
  263.     i= x-offset+begmark;
  264.     deleteline((i>0 ? i : 0),cursory);
  265.     if (!x && begmark) { 
  266.         begdim(); 
  267.         putch('<'); 
  268.         enddim(); 
  269.         }
  270.     while (x < SWIDTH+offset-begmark && (c=text[cp++])) {
  271.         if (c == '\t') {
  272.             for (i=tabwidth-x%tabwidth; i>0 && x<SWIDTH+offset-begmark; x++, i--)
  273.                 if (x >= offset) _os(DIRIO,' ');
  274.             }
  275.         else if (x++ >= offset) {
  276.             dispch(c);
  277.                 /* check for input and save if there */
  278.             if ( (cc=_os(DIRIO,0xff))) inbuf[inbufp++]=cc & ~PARBIT;
  279.             }
  280.         }
  281.     if (c && cursory < SHEIGHT) {
  282.         begdim(); 
  283.         putch('>'); 
  284.         enddim(); 
  285.         }
  286. }
  287.  
  288. calcoffset()
  289. {
  290.     /*for (offset=0; cursorx >= SWIDTH+offset-(offset>0); offset+=OFFWIDTH);*/
  291.     for (offset=(cursorx < lastoff ? 0 : lastoff);
  292.     cursorx >= SWIDTH+offset-(offset>0); offset+=OFFWIDTH);
  293.     return offset;
  294. }
  295.  
  296. resetcursor()
  297. {
  298.     int line, y;
  299.  
  300.     if (lastoff != calcoffset()) {
  301.         if (blockscroll) {
  302.             for (line=pfirst, y=topline; line <= plast; line++, y++)
  303.                 if (line != cline) putline(line,y);
  304.             }
  305.         putoffset();
  306.         rewrite(0,0);
  307.         lastoff=offset;
  308.         }
  309.     gotoxy(cursorx-offset+(offset>0),cursory);
  310. }
  311.  
  312. setstatusname()        /*copy just filename w/o path for 'putstatusline' */
  313. {
  314.     char *np,c;
  315.  
  316.     if (filename[0]=='\0') {
  317.         justfile[0]='\0';
  318.         /*_move(4,"\0\0\0\0",defext);*/
  319.         return;
  320.         }
  321.     np=filename;
  322.     while(*(np++));        /*find end*/
  323.         /*find last '\',if any*/
  324.     while( ((c=*(--np)) != '\\') && c!=':' && (np != filename)) {
  325.         if (c=='.') {
  326.             if ( *(np+1) == '\0') *(np) = '\0';
  327.             strcpy(defext,np);
  328.             }
  329.         }
  330.     if (!(*np)) strcpy(justfile,filename);
  331.     else {
  332.         _move(2,filename,justfile);
  333.         strcpy(&justfile[2],++np);
  334.         }
  335. }
  336.